﻿using System;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PickGold.Generic
{
	/// <summary>
	/// 增强数据存储的异步操作状态
	/// </summary>
	/// <typeparam name="DATA">增强的数据类型</typeparam>
	public class CAsyncResult<DATA> : IAsyncResult
	{
		private DATA _Data;
		private IAsyncResult _AsyncResult;

		/// <summary>
		/// 实例化一个增强数据存储的异步操作状态对象
		/// </summary>
		/// <param name="asyncResult">异步操作状态</param>
		public CAsyncResult(IAsyncResult asyncResult) : this(asyncResult, default(DATA)) { }

		/// <summary>
		/// 实例化一个增强数据存储的异步操作状态对象
		/// </summary>
		/// <param name="asyncResult">异步操作状态</param>
		/// <param name="data">增强的数据</param>
		public CAsyncResult(IAsyncResult asyncResult, DATA data)
		{
			this._AsyncResult = asyncResult;
			this._Data = data;
		}

		/// <summary>
		/// 增强的数据
		/// </summary>
		public DATA Data
		{
			get
			{
				return this._Data;
			}
		}

		/// <summary>
		/// 实际的异步操作状态
		/// </summary>
		public IAsyncResult AsyncResult
		{
			get
			{
				return this._AsyncResult;
			}
		}

		#region IAsyncResult 成员

		object IAsyncResult.AsyncState
		{
			get { return this._AsyncResult.AsyncState; }
		}

		WaitHandle IAsyncResult.AsyncWaitHandle
		{
			get { return this._AsyncResult.AsyncWaitHandle; }
		}

		bool IAsyncResult.CompletedSynchronously
		{
			get { return this._AsyncResult.CompletedSynchronously; }
		}

		bool IAsyncResult.IsCompleted
		{
			get { return this._AsyncResult.IsCompleted; }
		}

		#endregion
	}
}
